package com.example.animationviewdemo;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		AnimationView view1= (AnimationView) findViewById(R.id.view1);
		view1.setAdapter(new TestListAdapter(this));
		view1.start();
		AnimationView view2= (AnimationView) findViewById(R.id.view2);
		view2.setAdapter(new MySecondAnimViewAdapter(this));
		view2.start();
	}

	class TestListAdapter extends BaseAnimViewAdapter {
		private Context context;
		private List<String> lists = new ArrayList<String>();

		public TestListAdapter(Context context) {
			this.context = context;
			for (int i = 0; i < 100; ++i) {
				lists.add(UUID.randomUUID().toString());
			}
		}

		@Override
		public int getCount() {
			return lists.size();
		}

		@Override
		public Object getItem(int position) {
			return lists.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = LayoutInflater.from(context).inflate(
						R.layout.anim_layout, null);
			}
			TextView textView = (TextView) convertView.findViewById(R.id.text);
			textView.setText(lists.get(position));
			return convertView;
		}

		@Override
		public int getItemViewType(int position) {
			return IGNORE_ITEM_VIEW_TYPE;
		}

		@Override
		public int getViewTypeCount() {
			return 0;
		}

	}
}
